package com.zhaoxi.project.mes.service.impl;

import java.util.List;
import com.zhaoxi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.zhaoxi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.zhaoxi.project.mes.domain.MesWorkshopLine;
import com.zhaoxi.project.mes.mapper.MesWorkshopMapper;
import com.zhaoxi.project.mes.domain.MesWorkshop;

/**
 * 生产车间Service业务层处理
 * 
 * @author zhaoxi
 * @date 2023-08-28
 */
@Service
public class MesWorkshopServiceImpl
{
    @Autowired
    private MesWorkshopMapper mesWorkshopMapper;

    /**
     * 查询生产车间
     * 
     * @param id 生产车间主键
     * @return 生产车间
     */
    
    public MesWorkshop selectMesWorkshopById(Long id)
    {
        return mesWorkshopMapper.selectMesWorkshopById(id);
    }

    /**
     * 查询生产车间列表
     * 
     * @param mesWorkshop 生产车间
     * @return 生产车间
     */
    
    public List<MesWorkshop> selectMesWorkshopList(MesWorkshop mesWorkshop)
    {
        return mesWorkshopMapper.selectMesWorkshopList(mesWorkshop);
    }

    /**
     * 新增生产车间
     * 
     * @param mesWorkshop 生产车间
     * @return 结果
     */
    @Transactional
    
    public int insertMesWorkshop(MesWorkshop mesWorkshop)
    {
        mesWorkshop.setCreateTime(DateUtils.getNowDate());
        int rows = mesWorkshopMapper.insertMesWorkshop(mesWorkshop);
        insertMesWorkshopLine(mesWorkshop);
        return rows;
    }

    /**
     * 修改生产车间
     * 
     * @param mesWorkshop 生产车间
     * @return 结果
     */
    @Transactional
    
    public int updateMesWorkshop(MesWorkshop mesWorkshop)
    {
        mesWorkshop.setUpdateTime(DateUtils.getNowDate());
        mesWorkshopMapper.deleteMesWorkshopLineByWorkshopId(mesWorkshop.getId());
        insertMesWorkshopLine(mesWorkshop);
        return mesWorkshopMapper.updateMesWorkshop(mesWorkshop);
    }

    /**
     * 批量删除生产车间
     * 
     * @param ids 需要删除的生产车间主键
     * @return 结果
     */
    @Transactional
    
    public int deleteMesWorkshopByIds(Long[] ids)
    {
        mesWorkshopMapper.deleteMesWorkshopLineByWorkshopIds(ids);
        return mesWorkshopMapper.deleteMesWorkshopByIds(ids);
    }

    /**
     * 删除生产车间信息
     * 
     * @param id 生产车间主键
     * @return 结果
     */
    @Transactional
    
    public int deleteMesWorkshopById(Long id)
    {
        mesWorkshopMapper.deleteMesWorkshopLineByWorkshopId(id);
        return mesWorkshopMapper.deleteMesWorkshopById(id);
    }

    /**
     * 新增车间l流水线信息
     * 
     * @param mesWorkshop 生产车间对象
     */
    public void insertMesWorkshopLine(MesWorkshop mesWorkshop)
    {
//        List<MesWorkshopLine> mesWorkshopLineList = mesWorkshop.getMesWorkshopLineList();
//        Long id = mesWorkshop.getId();
//        if (StringUtils.isNotNull(mesWorkshopLineList))
//        {
//            List<MesWorkshopLine> list = new ArrayList<MesWorkshopLine>();
//            for (MesWorkshopLine mesWorkshopLine : mesWorkshopLineList)
//            {
////                mesWorkshopLine.setWorkshopId(id);
//                list.add(mesWorkshopLine);
//            }
//            if (list.size() > 0)
//            {
//                mesWorkshopMapper.batchMesWorkshopLine(list);
//            }
//        }
    }
}
